﻿/*
 * KLF Headless Browser
 * Written by Kris Oye <kristianoye@gmail.com>
 * Copyright (C) 2011-2012.  All rights reserved.
 */
namespace KLF.Lib.Browser.Resources
{
    #region Using Statements

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using KLF.Lib.Browser.DOM.HTML;
    using KLF.Lib.Browser.DOM;
    using KLF.Lib.Browser.DOM.Interface;

    #endregion

    public class StyleRequest : ResourceRequest
    {
        /// <summary>
        /// Generates a Style request.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="target"></param>
        public StyleRequest(string path, ILoadableContent target)
            : base(path, target)
        {
            AssignValue = new AssignResource(LoadStyle);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="receiver"></param>
        /// <param name="source"></param>
        public void LoadStyle(ILoadableContent receiver, string source)
        {
            HTMLStyleElement style = receiver as HTMLStyleElement;
            HTMLLinkElement link = receiver as HTMLLinkElement;

            if (style != null)
            {
                style.RawCss = source;
            }
            else if (link != null)
            {
                link.RawCss = source;
            }
        }
    }
}
